package com.ita.controller;

import java.util.UUID;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.ita.pojo.Customer;
import com.ita.service.CustomerService;

@Controller
public class CustomerController {

	@Resource(name = "customerService")
	private CustomerService uService;

	@RequestMapping(value = "/regist", method = RequestMethod.POST)
	public String regist(String name, String pwd,String age) {

		Customer u = new Customer();
		u.setId(UUID.randomUUID().toString());
		u.setUname(name);
		u.setPassword(pwd);
		u.setAge(Integer.parseInt(age));
		int m = uService.regist(u);
		if (m == 1)
			return "login";
		else
			return "regist";
	}

	@RequestMapping(value = "/login", method = RequestMethod.POST)
	public String login(String name, String pwd) {

		Customer u = uService.login(name, pwd);
		if (u != null)
			return "success";
		else
			return "login";
	}

}
